#!/usr/bin/env python2.4
#
#


import pygame
from pygame.locals import *

def screen_open(wide, high, depth, fullscreen , doublebuffer):
	bpp 	= depth
	flags 	= HWSURFACE
	if fullscreen == 1:   
		flags = flags | FULLSCREEN
	if doublebuffer == 1: 
		flags = flags | DOUBLEBUF
	print "Checking mode %sx%s@%sbpp.\n" % (wide, high, depth)
	bpp =   pygame.display.mode_ok ( (wide, high) , flags, 16 )
	if bpp == 0:
		write("Mode not available.\n")
		return 0
	
	print "SDL Recommends %sx%s@%sbpp.\n" % (wide, high, bpp)
	_surface = pygame.display.set_mode( (wide, high) , flags, bpp)
	if(_surface):
		pass
		# SDL_WM_SetCaption("Eruta", "Eruta");
	return _surface


def surface_make(wide, high, alpha):
	flags = SWSURFACE 
	if (alpha):  
		flags = flags | SRCALPHA  
	else :
		flags = flags | SRCCOLORKEY
	aid = pygame.Surface( (wide, high), flags)
	return aid


def surface_load(filename):
    "Loads an image, prepares it for play."
    # file = os.path.join('share', 'image', filename)
    try:
        surface = pygame.image.load(filename)
    except pygame.error:
        raise SystemExit, 'Could not load image "%s" %s'%(file, pygame.get_error())
    return surface.convert_alpha()

def rect_make(x, y, high, wide):
	rect = pygame.Rect(x, y, high, wide)
	return rect;

import time

def main():
	pygame.init();
	screen  = screen_open(640, 480, 16, 1, 1)
	surf    = surface_load("../share/image/tile/tile_cursor.png")
	screen.fill(0xff0000);
	start = time.clock()
	times = 1000
	for i in range(0, times):
		for ll in range (0,3):
			for xx in range(0, 16):
				for yy in range(0, 12):
					screen.blit(surf, (xx*40, yy*40))
		pygame.display.flip()
		print "Index %s" % i
		
	stop 	= time.clock()
	delta 	= stop - start
	reti 	= delta / (times + 0.0)
	fps  	= (times + 0.0) / ( (stop - start) / 1000000.0) 
	print "Time: %s ms, FPS: %s\n, Delta%s, Times %s (%s %s)" % (reti, fps, delta, times, start, stop);	
	return 0


main()
